package com.pinyougou.manager.controller;

import java.util.List;

import com.alibaba.dubbo.config.annotation.Reference;
import entity.PageResult;
import entity.Result;
import org.springframework.web.bind.annotation.*;

import com.pinyougou.pojo.TbBrand;
import com.pinyougou.sellergoods.service.BrandService;

@RestController
@RequestMapping("/brand")
public class BrandController {

	@Reference
	private BrandService brandService;

	@RequestMapping("/findAll")
	//查询所有类别
	public List<TbBrand> findAll(){
		return brandService.findAll();		
	}



	@RequestMapping("/findPage")
	//查询所有类别  （分页）
	public PageResult findPage( @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize) {

		return brandService.findPage(pageNum,pageSize);
	}


	@RequestMapping("/add")
	public Result add(@RequestBody TbBrand brand) {
		Result result = null;
		try {
			result = brandService.add(brand);
		}catch (Exception e){
			result = new Result(false,e.getMessage());
		}
		return result;
	}


	@RequestMapping("/findOne")
	/* 查询类别*/
	public TbBrand findOne(Long id) {

		TbBrand brand = brandService.findOne(id);

		return brand;
	}


	@RequestMapping("/update")
	/* 修改类别*/
	public Result update(@RequestBody TbBrand brand) {
		Result result = null;
		try {
			 brandService.update(brand);
			 result = new Result(true,"修改成功");
		}catch (Exception e){
			result = new Result(false,e.getMessage());
		}
		return result;
	}


	@RequestMapping("/delete")
	/* 删除类别*/
	public Result delete(Long[] ids) {
		Result result = null;
		try {
			brandService.delete(ids);
			result = new Result(true,"删除成功");
		}catch (Exception e){
			result = new Result(false,e.getMessage());
		}
		return result;
	}


	@RequestMapping("/search")
	/* 站内搜索  （分页）*/
	public PageResult search(@RequestBody TbBrand tbBrand, int pageNum, int pageSize) {
		return brandService.findPage(tbBrand,pageNum,pageSize);
	}


}
